#include<iostream>
#include<deque>
using namespace std;
typedef long long ll;
const int N = 500010;

ll a[N];
int n, m;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	cin >> n >> m;
	for (int i = 1;i <= n;i++)
	{
		cin >> a[i];
		a[i] += a[i - 1];
	}

	deque<int> q;
	q.push_back(0);
	ll max_sum = -1e18;

	for (int i = 1;i <= n;i++)
	{
		while (!q.empty() && q.front() < i - m)
		{
			q.pop_front();
		}
		if (!q.empty())
		{
			max_sum = max(max_sum, a[i] - a[q.front()]);
		}
		while (!q.empty() && a[q.back()] >= a[i])
		{
			q.pop_back();
		}
		q.push_back(i);
	}
	cout << max_sum << endl;
	return 0;
}